
#include <iostream>



int reverse(int n)
{
	if (-10 < n && n <10)
	{
		return n;
	}

	bool minos = false;
	if (n < 0)
	{
		n = -n;
		minos = true;
	}

	int result = 0;
	while(n > 0)
	{
		int k = n % 10;
		int max = 0x7FFFFFFF;

		if (result > max / 10)
		{
			return -1;
		}

		result = result * 10 + k;

		n = n / 10;

		if (result < 0)
		{
		 	return -1;
		}
	}

	if (minos == true)
	{
		result = - result;
	}

	return result;
}

char * reverse(const char * src)
{
	if (src == NULL) return NULL;

	int len = strlen(src);
	char * tmp = (char *)malloc(len);
	int i = 0;
	while(*src != '\0')
	{
		tmp[i] = *src;
		src++;
	}
	
	tmp[len - 1] = '\0';
	printf("%s\n", tmp);

	return tmp;
}


int main(int argc, char const *argv[])
{

	int n = -1234567812;
	int m = reverse(n);
	printf("%d -> %d\n", n, m);

	const char * str = "hello";
	char * tmp = reverse(str);
	printf("%s\n", tmp);

	return 0;
}
